package com.zggk.iroad.greendao;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.zggk.iroad.db.CzfaInfo;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "t_czfa".
*/
public class CzfaInfoDao extends AbstractDao<CzfaInfo, Long> {

    public static final String TABLENAME = "t_czfa";

    /**
     * Properties of entity CzfaInfo.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, Long.class, "id", true, "id");
        public final static Property GCXM = new Property(1, String.class, "GCXM", false, "GCXM");
        public final static Property GCXMID = new Property(2, String.class, "GCXMID", false, "GCXMID");
        public final static Property JSGS = new Property(3, String.class, "JSGS", false, "JSGS");
        public final static Property SL = new Property(4, String.class, "SL", false, "SL");
        public final static Property DW = new Property(5, String.class, "DW", false, "DW");
        public final static Property ParentId = new Property(6, Long.class, "parentId", false, "PARENT_ID");
    }

    private Query<CzfaInfo> handleInfo_CZFAQuery;

    public CzfaInfoDao(DaoConfig config) {
        super(config);
    }
    
    public CzfaInfoDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"t_czfa\" (" + //
                "\"id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id
                "\"GCXM\" TEXT," + // 1: GCXM
                "\"GCXMID\" TEXT," + // 2: GCXMID
                "\"JSGS\" TEXT," + // 3: JSGS
                "\"SL\" TEXT," + // 4: SL
                "\"DW\" TEXT," + // 5: DW
                "\"PARENT_ID\" INTEGER NOT NULL );"); // 6: parentId
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"t_czfa\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, CzfaInfo entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String GCXM = entity.getGCXM();
        if (GCXM != null) {
            stmt.bindString(2, GCXM);
        }
 
        String GCXMID = entity.getGCXMID();
        if (GCXMID != null) {
            stmt.bindString(3, GCXMID);
        }
 
        String JSGS = entity.getJSGS();
        if (JSGS != null) {
            stmt.bindString(4, JSGS);
        }
 
        String SL = entity.getSL();
        if (SL != null) {
            stmt.bindString(5, SL);
        }
 
        String DW = entity.getDW();
        if (DW != null) {
            stmt.bindString(6, DW);
        }
        stmt.bindLong(7, entity.getParentId());
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, CzfaInfo entity) {
        stmt.clearBindings();
 
        Long id = entity.getId();
        if (id != null) {
            stmt.bindLong(1, id);
        }
 
        String GCXM = entity.getGCXM();
        if (GCXM != null) {
            stmt.bindString(2, GCXM);
        }
 
        String GCXMID = entity.getGCXMID();
        if (GCXMID != null) {
            stmt.bindString(3, GCXMID);
        }
 
        String JSGS = entity.getJSGS();
        if (JSGS != null) {
            stmt.bindString(4, JSGS);
        }
 
        String SL = entity.getSL();
        if (SL != null) {
            stmt.bindString(5, SL);
        }
 
        String DW = entity.getDW();
        if (DW != null) {
            stmt.bindString(6, DW);
        }
        stmt.bindLong(7, entity.getParentId());
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public CzfaInfo readEntity(Cursor cursor, int offset) {
        CzfaInfo entity = new CzfaInfo( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // GCXM
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // GCXMID
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // JSGS
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // SL
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // DW
            cursor.getLong(offset + 6) // parentId
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, CzfaInfo entity, int offset) {
        entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setGCXM(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setGCXMID(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setJSGS(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setSL(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setDW(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setParentId(cursor.getLong(offset + 6));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(CzfaInfo entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(CzfaInfo entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(CzfaInfo entity) {
        return entity.getId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "CZFA" to-many relationship of HandleInfo. */
    public List<CzfaInfo> _queryHandleInfo_CZFA(Long parentId) {
        synchronized (this) {
            if (handleInfo_CZFAQuery == null) {
                QueryBuilder<CzfaInfo> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.ParentId.eq(null));
                handleInfo_CZFAQuery = queryBuilder.build();
            }
        }
        Query<CzfaInfo> query = handleInfo_CZFAQuery.forCurrentThread();
        query.setParameter(0, parentId);
        return query.list();
    }

}
